<?php

	add_action('init', 'add_textareas', 2);
	
	function add_textareas(){
		
		add_action( 'edit_form_advanced', 'project_overview_editor');
		add_action( 'edit_form_advanced', 'location_editor' );
		add_action( 'edit_form_advanced', 'building_features_and_plans_editor');
		add_action( 'edit_form_advanced', 'unit_features_and_plans_editor');
		add_action( 'edit_form_advanced', 'amenities_editor');	
		
		
	}
	
	
	/* Project Overview */
	function project_overview_editor(){
		global $post;
		if( $post->post_type == 'dmci_projects' ) {
			$content = get_post_meta($post->ID, 'dmci_project_overview', true);
			echo '<h3 class="hndle">Project Overview</h3>';
			wp_editor( $content, 'dmci_project_overview' );
		}
	}
	
	add_action('save_post', 'save_project_overview_editor');
	
	function save_project_overview_editor($post_id){
		global $post;
		
		if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {  
			return $post_id;
		}
		
		if( !isset($_POST['post_type']) || 'dmci_projects' != $_POST['post_type']) {  
		  if(!current_user_can('edit_page', $post_id)) {  
			return $post_id;  
		  } 
		} 
		else {  
			if(!current_user_can('edit_page', $post_id)) { 
				
				return $post_id;  
			} 
		}
		
		if( isset($post) && $post->post_type == "dmci_projects" ) {
			update_post_meta($post_id, 'dmci_project_overview', $_POST['dmci_project_overview']); 
		}
		
	}
	
	/* End Project Overview*/
	
	/* Location and Vicinity */
	function location_editor() {
		global $post;
		if( $post->post_type == 'dmci_projects' ) {
			$content = get_post_meta($post->ID, 'dmci_location_vicinity', true);
			echo '<h3 class="hndle">Location and Vicinity Map</h3>';
			wp_editor( $content, 'dmci_location_vicinity' );
		}
	}
	
	add_action('save_post', 'save_location_editor');
	
	function save_location_editor($post_id){
		global $post;
		
		if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {  
			return $post_id;
		}
		
		if( !isset($_POST['post_type']) || 'dmci_projects' != $_POST['post_type']) {  
		  if(!current_user_can('edit_page', $post_id)) {  
			return $post_id;  
		  } 
		} 
		else {  
			if(!current_user_can('edit_page', $post_id)) { 
				
				return $post_id;  
			} 
		}
				
		if( isset($post) && $post->post_type == "dmci_projects" ) {
			update_post_meta($post_id, 'dmci_location_vicinity', $_POST['dmci_location_vicinity']); 
		}
		
	}
	/* End Location and Vicinity */
	
	/* Building Features and Plans */
	function building_features_and_plans_editor() {
		global $post;
		if( $post->post_type == 'dmci_projects' ) {
			$content = get_post_meta($post->ID, 'dmci_building_features_and_plans', true);
			echo '<h3 class="hndle">Building Features and Plans</h3>';
			wp_editor( $content, 'dmci_building_features_and_plans' );
		}
	}
	
	add_action('save_post', 'save_building_features_and_plans');
	
	function save_building_features_and_plans($post_id){
		global $post;
		
		if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {  
			return $post_id;
		}
		
		if( !isset($_POST['post_type']) || 'dmci_projects' != $_POST['post_type']) {  
		  if(!current_user_can('edit_page', $post_id)) {  
			return $post_id;  
		  } 
		} 
		else {  
			if(!current_user_can('edit_page', $post_id)) { 
				
				return $post_id;  
			} 
		}
				
		if( isset($post) && $post->post_type == "dmci_projects" ) {
			update_post_meta($post_id, 'dmci_building_features_and_plans', $_POST['dmci_building_features_and_plans']); 
		}
		
	}
	/* End Building Features and Plans */
	
	/* Unit Features and Plans */
	function unit_features_and_plans_editor() {
		global $post;
		if( $post->post_type == 'dmci_projects' ) {
			$content = get_post_meta($post->ID, 'dmci_unit_features_and_plans', true);
			echo '<h3 class="hndle">Unit Features and Plans</h3>';
			wp_editor( $content, 'dmci_unit_features_and_plans' );
		}
	}
	
	add_action('save_post', 'save_unit_features_and_plans');
	
	function save_unit_features_and_plans($post_id){
		global $post;
		
		if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {  
			return $post_id;
		}
		
		if( !isset($_POST['post_type']) || 'dmci_projects' != $_POST['post_type']) {  
		  if(!current_user_can('edit_page', $post_id)) {  
			return $post_id;  
		  } 
		} 
		else {  
			if(!current_user_can('edit_page', $post_id)) { 
				
				return $post_id;  
			} 
		}
				
		if( isset($post) && $post->post_type == "dmci_projects" ) {
			update_post_meta($post_id, 'dmci_unit_features_and_plans', $_POST['dmci_unit_features_and_plans']); 
		}
		
	}
	/* End Unit Features and Plans */
	
	/* Amenities */
	function amenities_editor() {
		global $post;
		if( $post->post_type == 'dmci_projects' ) {
			$content = get_post_meta($post->ID, 'dmci_amenities', true);
			echo '<h3 class="hndle">Amenities</h3>';
			wp_editor( $content, 'dmci_amenities' );
		}
	}
	
	add_action('save_post', 'save_amenities');
	
	function save_amenities($post_id){
		global $post;
		
		if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {  
			return $post_id;
		}
		
		if( !isset($_POST['post_type']) || 'dmci_projects' != $_POST['post_type']) {  
		  if(!current_user_can('edit_page', $post_id)) {  
			return $post_id;  
		  } 
		} 
		else {  
			if(!current_user_can('edit_page', $post_id)) { 
				
				return $post_id;  
			} 
		}
		
		
		if( isset($post) && $post->post_type == "dmci_projects" ) {
			update_post_meta($post_id, 'dmci_amenities', $_POST['dmci_amenities']); 
		}
		
		
	}
	/* End Amenities*/